package cn.wolfcode.ssm.web.controller;


import cn.wolfcode.ssm.domain.OperationLog;
import cn.wolfcode.ssm.service.IOperationLogService;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.qo.JsonResult;
import cn.wolfcode.ssm.util.RequireAnnotation;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/operationLog")
public class OperationLogController {

    @Autowired
    private IOperationLogService operationLogService;


    @RequireAnnotation(name = "操作日志页面",expression = "operationLog:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<OperationLog> pageInfo = operationLogService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "log/operationLog";
    }

    @RequestMapping("/delete")
    @RequireAnnotation(name = "操作日志删除",expression = "operationLog:delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            operationLogService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequireAnnotation(name = "操作日志新增/编辑",expression = "operationLog:saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(OperationLog operationLog){
        if (operationLog.getId() != null) {
            operationLogService.update(operationLog);
        }else {
            operationLogService.save(operationLog);
        }
        return new JsonResult();
    }
}
